package uoa.assignment.game;

import uoa.assignment.character.GameCharacter;
import uoa.assignment.character.Monster;

public class Game {
    
    public Map map;
    
    Game (int height, int width) {
        this.map = new Map(height,width);
        map.printLayout();
    }
    			
    public Map getMap() {
        return this.map;
    }
    
    public boolean nextRound (String input) {
        if(map.characters[0].getHealth()<=0){
            for(GameCharacter ch:map.characters)
            {
                if(ch.getHealth()!=0)
                {
                    break;
                }
                System.out.println("YOU HAVE WON!");
            }
        }
        GameLogic.moveCharacter(input,map,map.characters[0]);
        System.out.printf("Player is moving %s\n",input);
        for(int i=1;i<4;i++)
        {
            String monsterInput=new Monster("monster").decideMove();
            GameLogic.moveCharacter(monsterInput, map, map.characters[i]);
            System.out.printf("Monster%d is moving %s\n",i,monsterInput);
        }
        for(int i=0;i<4;i++)
        {
            if(i==0)
            {
                System.out.printf("Health Player: %d\n",map.characters[0].getHealth());
            }
            else
            {
                System.out.printf("Health Monster%d: %d\n",i,map.characters[i].getHealth());
            }
        }
        System.out.println();
        map.printLayout();
        for(GameCharacter ch: map.characters)
        {
            if(ch!=map.characters[0]&&!map.layout[ch.row][ch.column].equals("x"))
            {
                System.out.println("YOU HAVE WON!");
                return false;
            }
            if(map.characters[0].getHealth()<=0)
            {
                System.out.println("YOU HAVE DIED!");
                return true;
            }


        }
        return true;
    }
   
}